package com.tang.chat.conrtoller;

import com.tang.chat.pojo.Result;
import com.tang.chat.pojo.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @author tmh
 * @date 2024/5/5 15:45
 * @description
 */
@RestController
public class UserController {

    @GetMapping("/login")
    public Result login(@RequestParam String username, HttpSession session) {
        Result result = new Result();
/*        if (user != null & "123".equals(user.getPassword())) {
            result.setFlag(true);
            //将数据存储到session对象中
            session.setAttribute("user", user.getUsername());
        } else {
            result.setFlag(false);
            result.setMessage("登陆失败");
            return result;
        }*/
        result.setFlag(true);
        result.setMessage("登录成功");
        session.setAttribute("user", username);
        return result;
    }

    /**
     * 获取用户名
     * @param session
     * @return
     */
    @GetMapping("/getUsername")
    public String getUsername(HttpSession session){
        String username = (String) session.getAttribute("user");
        return username;
    }
}
